package com.nacrtstudio.webgiftshop.model.shop.beans;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

import com.nacrtstudio.webgiftshop.core.beans.BaseBean;
import com.nacrtstudio.webgiftshop.model.shop.Address;
import com.nacrtstudio.webgiftshop.model.shop.Cart;
import com.nacrtstudio.webgiftshop.model.shop.Comment;
import com.nacrtstudio.webgiftshop.model.shop.Order;
import com.nacrtstudio.webgiftshop.model.shop.User;
import com.nacrtstudio.webgiftshop.util.shop.Role;

@Entity
public class UserBean extends BaseBean implements User{
	private String avatar="layout/images/avatar.jpg";
	private String firstName;
	private String lastName;
	private String eMail;
	private Date dateOfBirth;
	private String phoneNumber;
	private Address address;
	private String username;
	private String password;

	private Date created = new Date();

	private Cart cart;
	private Set<Order> orders;
	private Set<Comment> comments;
	
	private Long facebookId;
	private boolean accountLocked;
	private boolean credentialsExpired;
	private Set<Role> roles = new HashSet<Role>();
	
	
	
	public String getAvatar() {
		return avatar;
	}
	public void setAvatar(String avatar) {
		this.avatar = avatar;
	}
	public String getFirstName() {
		return firstName;
	}
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	public String getLastName() {
		return lastName;
	}
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	public String geteMail() {
		return eMail;
	}
	public void seteMail(String eMail) {
		this.eMail = eMail;
	}
	public Date getDateOfBirth() {
		return dateOfBirth;
	}
	public void setDateOfBirth(Date dateOfBirth) {
		this.dateOfBirth = dateOfBirth;
	}
	public String getPhoneNumber() {
		return phoneNumber;
	}
	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}
	@OneToOne(cascade=CascadeType.ALL,targetEntity=AddressBean.class)
	public Address getAddress() {
		return address;
	}
	public void setAddress(Address address) {
		this.address = address;
	}
	
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public Date getCreated() {
		return created;
	}
	public void setCreated(Date created) {
		this.created = created;
	}
	
	
	@OneToOne(cascade=CascadeType.ALL,targetEntity=CartBean.class)
	@LazyCollection(LazyCollectionOption.FALSE)
	public Cart getCart() {
		return cart;
	}
	public void setCart(Cart cart) {
		this.cart = cart;
	}
	@OneToMany(mappedBy="user",targetEntity=OrderBean.class)
	@LazyCollection(LazyCollectionOption.FALSE)
	public Set<Order> getOrders() {
		return orders;
	}
	public void setOrders(Set<Order> orders) {
		this.orders = orders;
	}
	@OneToMany(mappedBy="user",targetEntity=CommentBean.class)
	public Set<Comment> getComments() {
		return comments;
	}
	public void setComments(Set<Comment> comments) {
		this.comments = comments;
	}
	
	
	
	public Long getFacebookId() {
		return facebookId;
	}
	public void setFacebookId(Long facebookId) {
		this.facebookId = facebookId;
	}
	public boolean isAccountLocked() {
		return accountLocked;
	}
	public void setAccountLocked(boolean accountLocked) {
		this.accountLocked = accountLocked;
	}
	public boolean isCredentialsExpired() {
		return credentialsExpired;
	}
	public void setCredentialsExpired(boolean credentialsExpired) {
		this.credentialsExpired = credentialsExpired;
	}
	
	
	@ElementCollection
	@CollectionTable(name="CustomerRoles", joinColumns=@JoinColumn(name="customerroles"))
	@Column(name="roles")
	@LazyCollection(LazyCollectionOption.FALSE)
	public Set<Role> getRoles() {
		return roles;
	}
	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}
}
